﻿using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using PMS.SANY.Util;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace PMS.SANY.Entity
{
    /// <summary>
    /// 物料缓存料位
    /// </summary>
    public partial class StorageLocation: BusEntity
    {
        /// <summary>
        /// 料位编码
        /// </summary>
        public string Code { get; set; }
        /// <summary>
        /// 电气编码
        /// </summary>
        public Int16 ElectricCode { set; get; }
        /// <summary>
        /// 料位名称
        /// </summary>
        public string Name { get; set; }

        /// <summary>
        /// 所属缓存区编号
        /// </summary>
        public string StorageArealId { set; get; }
    }

    public partial class StorageLocation : BusEntity
    {
        /// <summary>
        /// 缓存区
        /// </summary>
        public StorageArea Storage { set; get; }
    }

    /// <summary>
    /// 实体配置
    /// OnModelCreating
    /// </summary>
    public class StorageLocationTypeConfig : BusEntityTypeConfig<StorageLocation>, IEntityTypeConfiguration<StorageLocation>
    {
        public override void Configure(EntityTypeBuilder<StorageLocation> builder)
        {
            base.Configure(builder);

            #region 主外键关系
            builder.HasOne(p => p.Storage).WithMany(p => p.Locations).HasForeignKey(p => p.StorageArealId);
            #endregion

            #region 字段属性:最大长度,是否必需,默认值
            builder.Property(p => p.Code).HasMaxLength(EntityDefinition.DefSmallColLen).IsRequired();
            builder.Property(p => p.Name).HasMaxLength(EntityDefinition.DefSmallColLen).IsRequired();
            builder.Property(p => p.StorageArealId).HasMaxLength(EntityDefinition.DefSmallColLen).IsRequired();
            #endregion

            #region 备注
            builder.HasComment("物料缓存料位");
            builder.Property(p => p.Code).HasComment("料位编码");
            builder.Property(p => p.Name).HasComment("料位名称");
            builder.Property(p => p.StorageArealId).HasComment("所属缓存区编号");
            #endregion

            #region 种子数据
            //for (Int16 idx = 1; idx < 16; idx++)
            //{
            //    builder.HasData(new StorageLocation { Id = idx.ToString(), Code = idx.ToString() + "#", Name = idx.ToString() + "#料位", ElectricCode = idx, StorageArealId = "HC1008", CreateUserId = "1", ModifyUserId = "1" });
            //}
            #endregion
        }
    }
}
